package com.bj.dz.service.impl;

import com.bj.dz.entity.WaterBangData;
import com.bj.dz.mapper.WaterBangDataMapper;
import com.bj.dz.service.WaterBangDataService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class WaterBangDataServiceImpl implements WaterBangDataService {

    @Resource
    private WaterBangDataMapper waterBangDataMapper;

    public WaterBangData getWaterBangDataById(Integer id){
        return waterBangDataMapper.getWaterBangDataById(id);
    }

    public List<WaterBangData>	getWaterBangDataListByMap(Map<String,Object> param){
        return waterBangDataMapper.getWaterBangDataListByMap(param);
    }

    public Integer getWaterBangDataCountByMap(Map<String,Object> param){
        return waterBangDataMapper.getWaterBangDataCountByMap(param);
    }

    @Transactional
    public boolean addWaterBangData(WaterBangData waterBangData){
            return waterBangDataMapper.insertWaterBangData(waterBangData)>0?true:false;
    }

    @Transactional
    public boolean modifyWaterBangData(WaterBangData waterBangData){
        return waterBangDataMapper.updateWaterBangData(waterBangData)>0?true:false;
    }

    @Transactional
    public boolean deleteWaterBangDataById(Integer id){
        return waterBangDataMapper.deleteWaterBangDataById(id)>0?true:false;
    }

    public Page<WaterBangData> queryWaterBangDataPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = waterBangDataMapper.getWaterBangDataCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<WaterBangData> waterBangDataList = waterBangDataMapper.getWaterBangDataListByMap(param);
        page.setRows(waterBangDataList);
        return page;
    }

}
